﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace AxeFrog.Data
{
	/// <summary>
	/// Decorates a list of entities with information about the broad result set that they would
	/// otherwise be a part of, including page number, total records matching the query, etc.
	/// </summary>
	/// <typeparam name="T">The type of entity returned in the query</typeparam>
	public class DataPage<T> : IEnumerable<T>
	{
		/// <summary>
		/// The total number of records in the non-paged result set
		/// </summary>
		public int TotalRecords { get; set; }
		/// <summary>
		/// The total number of pages containing records in the non-paged result set
		/// </summary>
		public int TotalPages { get; set; }
		/// <summary>
		/// The 1-based index of the page of results returned
		/// </summary>
		public int PageNumber { get; set; }
		/// <summary>
		/// The number of records to be found in a standard page of results
		/// </summary>
		public int PageSize { get; set; }
		/// <summary>
		/// Indicates the number of the first record on this page. e.g. For PageNumber=2 and PageSize=15, FirstRecordNumber would be 16.
		/// </summary>
		public int FirstRecordNumber { get { return (PageNumber - 1) * PageSize; } }
		/// <summary>
		/// The current page of results returned from the query
		/// </summary>
		public List<T> Records { get; set; }

		public IEnumerator<T> GetEnumerator()
		{
			return Records.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}
	}
}
